package com.macgoo.game;

import java.io.IOException;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import javax.servlet.http.*;

import com.macgoo.game.dal.QQNumberDAO;
import com.macgoo.game.dal.entity.QQNumber;
import com.macgoo.game.util.LogUtil;
import com.macgoo.util.HttpHelper;
import com.sonalb.net.http.cookie.CookieJar;

@SuppressWarnings("serial")
public class StealQFarmServlet extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		resp.setContentType("image/jpeg");
		HttpHelper hp = new HttpHelper();
		byte[] file = hp.GetFile("http://ptlogin2.qq.com/getimage?aid=15000101", hp.getCookieJar());
		resp.getOutputStream().write(file);
		CookieJar cookieJar = hp.getCookieJar();
		
		QQNumber qqNumber = new QQNumber();
		/*Iterator iterator = cookieJar.iterator();
		Vector v = new Vector();
		while (iterator.hasNext()) {
			Object object = iterator.next();
			v.add(object);
		}*/
		qqNumber.setCookieJar(Arrays.asList(hp.getCookieJar().toArray()));
		
		QQNumberDAO dao = new QQNumberDAO();
		dao.Clear();
		dao.Save(qqNumber);
		dao.Flush();
		
		
		List<QQNumber> list = dao.QueryAll();
		//dao.Close();
		for(QQNumber i : list) {
			LogUtil.WriteInfo(i.getId().toString());
			dao.Delect(i);
		}
		dao.Close();
		
		
	}
}
